package ych;

import static org.junit.Assert.assertTrue;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;
import robocode.control.testing.RobotTestBed;

/**
 * Check if the robot visits all the walls.
 *
 * @author Chris Young
 */
public class Behavior1 extends RobotTestBed {
  //check to see if the robot visited all the walls
  boolean visitedLeftWall = false;
  boolean visitedRightWall = false;
  boolean visitedBottomWall = false;
  boolean visitedUpperWall = false;

  /**
   * Specifies that SittingDuck and Boom01 are to be matched up in this test case.
   *
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.SittingDuck,ych.Boom01";
  }

  /**
   * This test runs for 10 round.
   *
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }

  /**
   * After each turn, check to see if we're at a wall. If so, set the corresponding flag.
   *
   * @param event Info about the current state of the battle.
   */
  @Override
  public void onTurnEnded(TurnEndedEvent event) {
    // Get the snapshot of the robot daCruzer 
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];
    
    // Get robot's current position
    double xPos = robot.getX();
    double yPos = robot.getY();
    // The set the width of all robots
    final double robotWidth = 40.0;

    // Checks to see if the robot visited the top left corner
    if ((xPos < robotWidth) && (yPos < robotWidth)) {
      visitedLeftWall = true;
    }
    if ((xPos < robotWidth && (yPos > (height - robotWidth)))) {
      visitedBottomWall = true;
    }
    if ((xPos > (width - robotWidth)) && (yPos < robotWidth)) {
      visitedUpperWall = true;
    }
    if ((xPos > (width - robotWidth) && (yPos > (height - robotWidth)))) {
      visitedRightWall = true;
    }

  }

  /**
   * After the battle, check to see that we've visited the walls.
   *
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue("Check Left Wall", visitedLeftWall);
    assertTrue("Check Right Wall", visitedRightWall);
    assertTrue("Check Bottom Wall", visitedBottomWall);
    assertTrue("Check Upper Wall", visitedUpperWall);

  }

}
